package jianzhiOffer;
//剑指 Offer 04. 二维数组中的查找
public class Num04_findNumberIn2DArray {
    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        if (matrix==null||matrix.length==0||matrix[0].length==0){
            return false;
        }

        int rowMax = matrix.length-1;
        int row = 0;
        int col = matrix[0].length-1;

        while (row<=rowMax && col>=0){
            if (matrix[row][col]<target){
                row++;

            }else if (matrix[row][col]>target){
                col--;
            }else {
                return true;
            }
        }
        return false;
    }
}
